﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace XB.Core.MemoryStore.Logger
{
    public class DefaultLogger : ILogger
    {
        public static ConcurrentQueue<string> Traces = new ConcurrentQueue<string>();
        public static ConcurrentQueue<string> InitTraces = new ConcurrentQueue<string>();

        public void TraceInfo(string message, params object[] args)
        {
            var text = string.Format("{0} {1}: {2}", Thread.CurrentThread.ManagedThreadId, DateTime.Now, string.Format(message, args));
            Traces.Enqueue(text);

            if (Traces.Count > 2000)
            {
                string result = null;
                Traces.TryDequeue(out result);
            }
        }

        public void Error(string message, Exception ex = null)
        {
            TraceInfo(string.Format("{0}, ex: {1}\r\nstack:{2}", message, ex == null ? "null" : ex.Message, ex == null ? "null" : ex.StackTrace));
        }
    }
}
